﻿using Microsoft.EntityFrameworkCore;
using miniMana.Data.MyDataBaseContext;
using miniMana.Entity;
using miniMana.Entity.EntityBase;
using miniMana.IService;
using miniMana.Repository.BaseRepository;
using miniMana.Repository.IRepositories;
using miniMana.Repository.Repositories;
using miniMana.Request;

namespace miniMana.Service
{
    public class UserService : IUserService
    {
        private readonly IAccountRepository _accountRepository;

        public UserService(IAccountRepository accountRepository)
        {
            _accountRepository = accountRepository;
        }

        public bool AddUser(AddUserRequest request)
        {
            var user = new User()
            {
                UserAddress = request.UserAddress,
                UserAge = request.UserAge,
                UserName = request.UserName,
                UserPwd = request.UserPwd,
            };
            //context.Users.Add(user);
            //context.SaveChanges();
            return true;
        }



        /// <summary>
        /// 获取账号
        /// </summary>
        /// <param name="account"></param>
        /// <returns></returns>
        public async Task<Account> GetAccountMsg(string account)
        {
            var xxx= await _accountRepository.Query().Where(t => t.Name == account).FirstOrDefaultAsync();

            return xxx;
        }

        public async Task UpdateLoginTime(Account account)
        {
            account.LastLoginTime = DateTime.Now;
            await _accountRepository.SaveAsync();
        }
    }
}